import 'dart:async';
import 'package:rxdart/rxdart.dart';

/*
Imagine you have a search field that triggers a REST API call if its text is changed. 
Doing an API call on every single key stroke is expensive. So you would like to only 
make a call if the user pauses for a moment. Exactly for this is debounce() it will 
swallow all incoming events if they are not followed by a pause.
*/
void main() {
  var subject = new PublishSubject<String>();

  subject.debounce(new Duration(milliseconds: 100)).listen((s) => print(s));

  subject.add('A');
  subject.add('AB');

  new Future.delayed(Duration(milliseconds: 200));

  subject.add("ABC");
// There is no output yet

  new Future.delayed(Duration(milliseconds: 700));

// now we receive the latest value: 'ABC'
}

//EOP
